﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace QuanLyBanHang.DAL
{
    public class PhieuNhap_DAL
    {
        dbConnection conn;
        public PhieuNhap_DAL()
        {
            conn = new dbConnection();
        }
        public bool insertPN(out int mapn, int manv, string mancc, long tonggia)
        {
            string query = "insertPN";
            SqlParameter[] p = new SqlParameter[5];
            p[0] = new SqlParameter("@manv", manv);
            p[1] = new SqlParameter("@mancc", mancc);
            p[2] = new SqlParameter("@ngaylap", DateTime.Now.Date);
            p[3] = new SqlParameter("@tong", tonggia);
            p[4] = new SqlParameter("@mapn", SqlDbType.Int);
            p[4].Direction = ParameterDirection.Output;
            bool kq = conn.execInsertProcedureQuery(query, p);
            mapn = int.Parse(p[4].Value.ToString());
            return kq;
        }
        public bool insertCTPN(int mapn, int masp, int soluong, int dongia)
        {
            string query = "insert into CHITIETPHIEUNHAP values(@mapn,@masp,@soluong,@dongia)";
            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter("@mapn", mapn);
            p[1] = new SqlParameter("@masp", masp);
            p[2] = new SqlParameter("@soluong", soluong);
            p[3] = new SqlParameter("@dongia", dongia);
            return conn.execInsertQuery(query, p);

        }
        public DataTable xemPN(int thang, int nam)
        {
            string query = "xemPN";
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@thang", thang);
            p[1] = new SqlParameter("@nam", nam);
            return conn.execSelectProcedureQuery(query, p);
        }
    }
}
